package com.vogue.family.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;
import android.widget.Toast;
import com.vogue.family.databinding.ActivitySignInBinding;
import com.vogue.family.ui.vm.SignInViewModel;

public class SignInActivity extends AppCompatActivity {

    private ActivitySignInBinding binding;
    private SignInViewModel viewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivitySignInBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        viewModel = new ViewModelProvider(this).get(SignInViewModel.class);

        binding.btnSignIn.setOnClickListener(view -> {
            if (binding.etAccount.getText().toString().trim().isEmpty()) {
                Toast.makeText(SignInActivity.this, "请输入账号", Toast.LENGTH_SHORT).show();
            }else if (binding.etPassword.getText().toString().trim().isEmpty()) {
                Toast.makeText(SignInActivity.this, "请输入密码", Toast.LENGTH_SHORT).show();
            } else {
                viewModel.onSignIn(binding.etAccount.getText().toString(),binding.etPassword.getText().toString());
            }
        });

        viewModel.getErrorMsg().observe(this,s -> {
            Toast.makeText(SignInActivity.this, s, Toast.LENGTH_SHORT).show();
        });


    }
}